#include "host_data.h"

void host_data_set_sv(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->sv != value)
    {
        _value = (value > host_data->displayRangeHigh) ? host_data->displayRangeHigh : value;
        _value = (_value < host_data->displayRangeLow) ? host_data->displayRangeLow : _value;
        host_data->sv = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, sv), (rt_uint8_t*)&host_data->sv, sizeof(host_data->sv));
        rt_kprintf("sv: %d\r\n", host_data->sv);
    }
}

void host_data_set_tempAlarmLow(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->tempAlarmLow != value)
    {
        _value = (value > host_data->displayRangeHigh) ? host_data->displayRangeHigh : value;
        _value = (_value < host_data->displayRangeLow) ? host_data->displayRangeLow : _value;
        host_data->tempAlarmLow = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempAlarmLow), (rt_uint8_t*)&host_data->tempAlarmLow, sizeof(host_data->tempAlarmLow));
        rt_kprintf("tempAlarmLow: %d\r\n", host_data->tempAlarmLow);
    }
}

void host_data_set_tempAlarmHigh(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->tempAlarmHigh != value)
    {
        _value = (value > host_data->displayRangeHigh) ? host_data->displayRangeHigh : value;
        _value = (_value < host_data->displayRangeLow) ? host_data->displayRangeLow : _value;
        host_data->tempAlarmHigh = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempAlarmHigh), (rt_uint8_t*)&host_data->tempAlarmHigh, sizeof(host_data->tempAlarmHigh));
        rt_kprintf("tempAlarmHigh: %d\r\n", host_data->tempAlarmHigh);
    }
}

void host_data_set_atEnable(rt_uint8_t value)
{
    if(host_data->atEnable != value)
    {
        if(value <= 1)
        {
            host_data->atEnable = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, atEnable), (rt_uint8_t*)&host_data->atEnable, sizeof(host_data->atEnable));
            rt_kprintf("atEnable: %d\r\n", host_data->atEnable);
        }
    }
}

void host_data_set_tecCtrlMode(rt_uint8_t value)
{
    if(host_data->tecCtrlMode != value)
    {
        if(value <= TEC_Ctrl_Mode_Hand)
        {
            host_data->tecCtrlMode = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tecCtrlMode), (rt_uint8_t*)&host_data->tecCtrlMode, sizeof(host_data->tecCtrlMode));
            rt_kprintf("tecCtrlMode: %d\r\n", host_data->tecCtrlMode);
        }
    }
}

void host_data_set_tecPower(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->tecPower != value)
    {
        _value = (value > host_data->tecMaxPower) ? host_data->tecMaxPower : value;
        _value = (_value < -host_data->tecMaxPower) ? -host_data->tecMaxPower : value;
        host_data->tecPower = _value;
        /* 此参数不存入存储器 */

        rt_kprintf("tecPower: %d\r\n", host_data->tecPower);
    }
}

void host_data_set_workMode(rt_uint8_t value)
{
    if(host_data->workMode != value)
    {
        if(value >= Work_Mode_Off && value <= Work_Mode_Hold)
        {
            host_data->workMode = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, workMode), (rt_uint8_t*)&host_data->workMode, sizeof(host_data->workMode));
            rt_kprintf("workMode: %d\r\n", host_data->workMode);
        }
    }
}

void host_data_set_pidKp(rt_uint16_t value)
{
    rt_uint16_t _value;
    if(host_data->pidKp != value)
    {
        _value = (value > PID_KP_MAX) ? PID_KP_MAX : value;
        host_data->pidKp = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, pidKp), (rt_uint8_t*)&host_data->pidKp, sizeof(host_data->pidKp));
        rt_kprintf("pidKp: %d\r\n", host_data->pidKp);
    }
}

void host_data_set_pidKi(rt_uint16_t value)
{
    rt_uint16_t _value;
    if(host_data->pidKi != value)
    {
        _value = (value > PID_KI_MAX) ? PID_KI_MAX : value;
        host_data->pidKi = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, pidKi), (rt_uint8_t*)&host_data->pidKi, sizeof(host_data->pidKi));
        rt_kprintf("pidKi: %d\r\n", host_data->pidKi);
    }
}

void host_data_set_pidKd(rt_uint16_t value)
{
    rt_uint16_t _value;
    if(host_data->pidKd != value)
    {
        _value = (value > PID_KD_MAX) ? PID_KD_MAX : value;
        host_data->pidKd = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, pidKd), (rt_uint8_t*)&host_data->pidKd, sizeof(host_data->pidKd));
        rt_kprintf("pidKd: %d\r\n", host_data->pidKd);
    }
}

void host_data_set_pidMode(rt_uint8_t value)
{
    if(host_data->pidMode != value)
    {
        if(value <= PID_Mode_C)
        {
            host_data->pidMode = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, pidMode), (rt_uint8_t*)&host_data->pidMode, sizeof(host_data->pidMode));
            rt_kprintf("pidMode: %d\r\n", host_data->pidMode);
        }
    }
}

void host_data_set_svOffset(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->svOffset != value)
    {
        _value = (value > SV_OFFSET_MAX) ? SV_OFFSET_MAX : value;
        _value = (_value < SV_OFFSET_MIN) ? SV_OFFSET_MIN : _value;
        host_data->svOffset = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, svOffset), (rt_uint8_t*)&host_data->svOffset, sizeof(host_data->svOffset));
        rt_kprintf("svOffset: %d\r\n", host_data->svOffset);
    }
}

void host_data_set_pvOffset(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->pvOffset != value)
    {
        _value = (value > PV_OFFSET_MAX) ? PV_OFFSET_MAX : value;
        _value = (_value < PV_OFFSET_MIN) ? PV_OFFSET_MIN : _value;
        host_data->pvOffset = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, pvOffset), (rt_uint8_t*)&host_data->pvOffset, sizeof(host_data->pvOffset));
        rt_kprintf("pvOffset: %d\r\n", host_data->pvOffset);
    }
}

void host_data_set_tecOutputDir(rt_uint8_t value)
{
    if(host_data->tecOutputDir != value)
    {
        if(value >= TEC_Output_Dir_Negative && value <= TEC_Output_Dir_Positive)
        {
            host_data->tecOutputDir = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tecOutputDir), (rt_uint8_t*)&host_data->tecOutputDir, sizeof(host_data->tecOutputDir));
            rt_kprintf("tecOutputDir: %d\r\n", host_data->tecOutputDir);
        }
    }
}

void host_data_set_tempSensorType(rt_uint8_t value)
{
    if(host_data->tempSensorType != value)
    {
        if(value >= Temp_Sensor_Type_TCJ && value <= Temp_Sensor_Type_NTC)
        {
            host_data->tempSensorType = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempSensorType), (rt_uint8_t*)&host_data->tempSensorType, sizeof(host_data->tempSensorType));
            rt_kprintf("tempSensorType: %d\r\n", host_data->tempSensorType);
        }
    }
}

void host_data_set_tempUnit(rt_uint8_t value)
{
    if(host_data->tempUnit != value)
    {
        if(value >= Temp_Unit_Type_Celsius && value <= Temp_Unit_Type_Fahrenheit)
        {
            host_data->tempUnit = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempUnit), (rt_uint8_t*)&host_data->tempUnit, sizeof(host_data->tempUnit));
            rt_kprintf("tempUnit: %d\r\n", host_data->tempUnit);
        }
    }
}

void host_data_set_decimalPointNbr(rt_uint8_t value)
{
    if(host_data->decimalPointNbr != value)
    {
        if(value >= Decimal_Point_Nbr_0 && value <= Decimal_Point_Nbr_2)
        {
            host_data->decimalPointNbr = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, decimalPointNbr), (rt_uint8_t*)&host_data->decimalPointNbr, sizeof(host_data->decimalPointNbr));
            rt_kprintf("decimalPointNbr: %d\r\n", host_data->decimalPointNbr);
        }
    }
}

void host_data_set_displayRangeLow(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->displayRangeLow != value)
    {
        _value = (value > DISPLAY_RANGE_MAX) ? DISPLAY_RANGE_MAX : value;
        _value = (_value < DISPLAY_RANGE_MIN) ? DISPLAY_RANGE_MIN : _value;
        host_data->displayRangeLow = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, displayRangeLow), (rt_uint8_t*)&host_data->displayRangeLow, sizeof(host_data->displayRangeLow));
        rt_kprintf("displayRangeLow: %d\r\n", host_data->displayRangeLow);
    }
}

void host_data_set_displayRangeHigh(rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->displayRangeHigh != value)
    {
        _value = (value > DISPLAY_RANGE_MAX) ? DISPLAY_RANGE_MAX : value;
        _value = (_value < DISPLAY_RANGE_MIN) ? DISPLAY_RANGE_MIN : _value;
        host_data->displayRangeHigh = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, displayRangeHigh), (rt_uint8_t*)&host_data->displayRangeHigh, sizeof(host_data->displayRangeHigh));
        rt_kprintf("displayRangeHigh: %d\r\n", host_data->displayRangeHigh);
    }
}

void host_data_set_filterDegree(rt_uint16_t value)
{
    if(host_data->filterDegree != value)
    {
        if(value <= FILTER_DEGREE_MAX)
        {
            host_data->filterDegree = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, filterDegree), (rt_uint8_t*)&host_data->filterDegree, sizeof(host_data->filterDegree));
            rt_kprintf("filterDegree: %d\r\n", host_data->filterDegree);
        }
    }
}

void host_data_set_mbSlaverAddr(rt_uint8_t value)
{
    rt_uint8_t _value;
    if(host_data->mbSlaverAddr != value)
    {
        _value = (value > MB_ADDR_MAX) ? MB_ADDR_MAX : value;
        _value = (_value < MB_ADDR_MIN) ? MB_ADDR_MIN : _value;
        host_data->mbSlaverAddr = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, mbSlaverAddr), (rt_uint8_t*)&host_data->mbSlaverAddr, sizeof(host_data->mbSlaverAddr));
        rt_kprintf("mbSlaverAddr: %d\r\n", host_data->mbSlaverAddr);
    }
}

void host_data_set_mbBaudrateID(rt_uint8_t value)
{
    if(host_data->mbBaudrateID != value)
    {
        if(value >= MB_Baudrate_ID_2400 && value <= MB_Baudrate_ID_38400)
        {
            host_data->mbBaudrateID = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, mbBaudrateID), (rt_uint8_t*)&host_data->mbBaudrateID, sizeof(host_data->mbBaudrateID));
            rt_kprintf("mbBaudrateID: %d\r\n", host_data->mbBaudrateID);
        }
    }
}

void host_data_set_powerOnAutoRun(rt_uint8_t value)
{
    if(host_data->powerOnAutoRun != value)
    {
        if(value <= 1)
        {
            host_data->powerOnAutoRun = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, powerOnAutoRun), (rt_uint8_t*)&host_data->powerOnAutoRun, sizeof(host_data->powerOnAutoRun));
            rt_kprintf("powerOnAutoRun: %d\r\n", host_data->powerOnAutoRun);
        }
    }
}

void host_data_set_steadyAlarmRange(rt_uint16_t value)
{
    rt_uint16_t _value;
    if(host_data->steadyAlarmRange != value)
    {
        _value = (value > STEAD_ALARM_MAX) ? STEAD_ALARM_MAX : value;
        host_data->steadyAlarmRange = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, steadyAlarmRange), (rt_uint8_t*)&host_data->steadyAlarmRange, sizeof(host_data->steadyAlarmRange));
        rt_kprintf("steadyAlarmRange: %d\r\n", host_data->steadyAlarmRange);
    }
}

void host_data_set_tecMaxPower(rt_uint8_t value)
{
    rt_uint8_t _value;
    if(host_data->tecMaxPower != value)
    {
        _value = (value > TEC_POWER_MAX) ? TEC_POWER_MAX : value;
        host_data->tecMaxPower = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tecMaxPower), (rt_uint8_t*)&host_data->tecMaxPower, sizeof(host_data->tecMaxPower));
        rt_kprintf("tecMaxPower: %d\r\n", host_data->tecMaxPower);
    }
}

void host_data_set_mbCrcEnable(rt_uint8_t value)
{
    if(host_data->mbCrcEnable != value)
    {
        if(value <= 1)
        {
            host_data->mbCrcEnable = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, mbCrcEnable), (rt_uint8_t*)&host_data->mbCrcEnable, sizeof(host_data->mbCrcEnable));
            rt_kprintf("mbCrcEnable: %d\r\n", host_data->mbCrcEnable);
        }
    }
}

void host_data_set_errorCode(rt_uint8_t value)
{
    if(host_data->errorCode != value)
    {
        host_data->errorCode = value;
        rt_kprintf("errorCode: %d\r\n", host_data->errorCode);
    }
}

void host_data_set_tempCalibPointNbr(rt_uint8_t value)
{
    rt_uint8_t _value;
    if(host_data->tempCalibPointNbr != value)
    {
        _value = (value >= 3 && value <= 10) ? value : 0;
        host_data->tempCalibPointNbr = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempCalibPointNbr), (rt_uint8_t*)&host_data->tempCalibPointNbr, sizeof(host_data->tempCalibPointNbr));
        rt_kprintf("tempCalibPointNbr: %d\r\n", host_data->tempCalibPointNbr);
    }
}

void host_data_set_tempCalibReal(rt_uint8_t index, rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->tempCalibReal[index] != value)
    {
        _value = (value > host_data->displayRangeHigh) ? host_data->displayRangeHigh : value;
        _value = (_value < host_data->displayRangeLow) ? host_data->displayRangeLow : _value;
        host_data->tempCalibReal[index] = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempCalibReal[index]), (rt_uint8_t*)&host_data->tempCalibReal[index], sizeof(host_data->tempCalibReal[index]));
        rt_kprintf("tempCalibReal[%d]: %d\r\n", index, host_data->tempCalibReal[index]);
    }
}

void host_data_set_tempCalibSet(rt_uint8_t index, rt_int16_t value)
{
    rt_int16_t _value;
    if(host_data->tempCalibSet[index] != value)
    {
        _value = (value > host_data->displayRangeHigh) ? host_data->displayRangeHigh : value;
        _value = (_value < host_data->displayRangeLow) ? host_data->displayRangeLow : _value;
        host_data->tempCalibSet[index] = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, tempCalibSet[index]), (rt_uint8_t*)&host_data->tempCalibSet[index], sizeof(host_data->tempCalibSet[index]));
        rt_kprintf("tempCalibSet[%d]: %d\r\n", index, host_data->tempCalibSet[index]);
    }
}

void host_data_set_progCurrentStep(rt_uint8_t value)
{
    RT_ASSERT(value >= 1 && value <= 16);

    if(host_data->progCurrentStep != value)
    {
        host_data->progCurrentStep = value;
        rt_kprintf("progCurrentStep: %d\r\n", host_data->progCurrentStep);
    }
}

void host_data_set_progTimeUnitAdjust(rt_uint8_t value)
{
    if(host_data->progTimeUnitAdjust != value)
    {
        if(value >= Prog_Time_Unit_Sec && value <= Prog_Time_Unit_Min)
        {
            host_data->progTimeUnitAdjust = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progTimeUnitAdjust), (rt_uint8_t*)&host_data->progTimeUnitAdjust, sizeof(host_data->progTimeUnitAdjust));
            rt_kprintf("progTimeUnitAdjust: %d\r\n", host_data->progTimeUnitAdjust);
        }
    }
}

void host_data_set_progTimeUnitHold(rt_uint8_t value)
{
    if(host_data->progTimeUnitHold != value)
    {
        if(value >= Prog_Time_Unit_Sec && value <= Prog_Time_Unit_Min)
        {
            host_data->progTimeUnitHold = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progTimeUnitHold), (rt_uint8_t*)&host_data->progTimeUnitHold, sizeof(host_data->progTimeUnitHold));
            rt_kprintf("progTimeUnitHold: %d\r\n", host_data->progTimeUnitHold);
        }
    }
}

void host_data_set_progStart(rt_uint8_t value)
{
    if(host_data->progStart != value)
    {
        if(value <= 1)
        {
            host_data->progStart = value;
            rt_kprintf("progStart: %d\r\n", host_data->progStart);
        }
    }
}
void host_data_set_progTempAcceptance(rt_uint8_t value)
{
    rt_uint8_t _value;
    if(host_data->progTempAcceptance != value)
    {
        _value = (value > PROG_TEMP_ACCEPTANCE_MAX) ? PROG_TEMP_ACCEPTANCE_MAX : value;
        host_data->progTempAcceptance = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progTempAcceptance), (rt_uint8_t*)&host_data->progTempAcceptance, sizeof(host_data->progTempAcceptance));
        rt_kprintf("progTempAcceptance: %d\r\n", host_data->progTempAcceptance);
    }
}

void host_data_set_progStepMode(rt_uint8_t index, rt_uint8_t value)
{
    rt_uint8_t _index;

    _index = (index > 7) ? 7 : index;
    if(host_data->progList[index].stepMode != value)
    {
        if(value >= Prog_Step_Mode_End && value <= Prog_Step_Mode_Next)
        {
            host_data->progList[index].stepMode = value;
            rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progList[index].stepMode), (rt_uint8_t*)&host_data->progList[index].stepMode, sizeof(host_data->progList[index].stepMode));
            rt_kprintf("progStep%dMode: %d\r\n", _index, host_data->progList[_index].stepMode);
        }
    }
}

void host_data_set_progStepSv(rt_uint8_t index, rt_int16_t value)
{
    rt_int16_t _value;
    rt_uint8_t _index;

    _index = (index > 7) ? 7 : index;
    if(host_data->progList[index].stepSv != value)
    {
        _value = (value > host_data->displayRangeHigh) ? host_data->displayRangeHigh : value;
        _value = (_value < host_data->displayRangeLow) ? host_data->displayRangeLow : _value;
        host_data->progList[index].stepSv = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progList[index].stepSv), (rt_uint8_t*)&host_data->progList[index].stepSv, sizeof(host_data->progList[index].stepSv));
        rt_kprintf("progStep%dSv: %d\r\n", _index, host_data->progList[_index].stepSv);
    }
}

void host_data_set_progStepAdjustTime(rt_uint8_t index, rt_uint16_t value)
{
    rt_uint8_t _index;

    _index = (index > 7) ? 7 : index;
    if(host_data->progList[index].stepAdjustTime != value)
    {
        host_data->progList[index].stepAdjustTime = value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progList[index].stepAdjustTime), (rt_uint8_t*)&host_data->progList[index].stepAdjustTime, sizeof(host_data->progList[index].stepAdjustTime));
        rt_kprintf("progStep%dAdjustTime: %d\r\n", _index, host_data->progList[_index].stepAdjustTime);
    }
}

void host_data_set_progStepHoldTime(rt_uint8_t index, rt_uint16_t value)
{
    rt_uint8_t _index;

    _index = (index > 7) ? 7 : index;
    if(host_data->progList[index].stepHoldTime != value)
    {
        host_data->progList[index].stepHoldTime = value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progList[index].stepHoldTime), (rt_uint8_t*)&host_data->progList[index].stepHoldTime, sizeof(host_data->progList[index].stepHoldTime));
        rt_kprintf("progStep%dHoldTime: %d\r\n", _index, host_data->progList[_index].stepHoldTime);
    }
}

void host_data_set_progStepLoopCnt(rt_uint8_t index, rt_uint8_t value)
{
    rt_uint8_t _value;
    rt_uint8_t _index;

    _index = (index > 7) ? 7 : index;
    if(host_data->progList[index].stepLoopCnt != value)
    {
        _value = (value > PROG_LOOP_CNT_MAX) ? PROG_LOOP_CNT_MAX : value;
        _value = (_value < PROG_LOOP_CNT_MIN) ? PROG_LOOP_CNT_MIN : _value;
        host_data->progList[index].stepLoopCnt = _value;
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progList[index].stepLoopCnt), (rt_uint8_t*)&host_data->progList[index].stepLoopCnt, sizeof(host_data->progList[index].stepLoopCnt));
        rt_kprintf("progStep%dLoopCnt: %d\r\n", _index, host_data->progList[_index].stepLoopCnt);
    }
}

void host_data_set_progStepNext(rt_uint8_t index, rt_uint8_t progStepNextNbr)
{
    rt_uint8_t _index;

    _index = (index > 7) ? 7 : index;
    if(host_data->progList[index].stepNext->stepNbr != progStepNextNbr)
    {
        host_data->progList[index].stepNext = &host_data->progList[progStepNextNbr];
        rt_device_write((rt_device_t)fram_dev, get_member_offset(struct Host_Data, progList[index].stepNext), (rt_uint8_t*)&host_data->progList[index].stepNext, sizeof(host_data->progList[index].stepNext));
        rt_kprintf("progStep%dNext: %d\r\n", _index, host_data->progList[_index].stepNext->stepNbr);
    }
}